package com.utils.sm;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 用于密码传递过程中的内存泄露风险
 *
 * @author SZYYYFPT003
 * @data 2023/02/20
 */
public class SecureStorage {
    private SecureStorage(){}
    private static final Logger logger = LoggerFactory.getLogger(SecureStorage.class);

    public static String getString(byte[] bytes){
        StringBuilder stringBuilder = new StringBuilder(0);
        try (BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(bytes)))) {
            String text = null;
            while ((text = br.readLine()) != null) {
                stringBuilder.append(text);
            }
        } catch (IOException e) {
            logger.error("SecureStorage setSafeArray IOException");
        }
        return stringBuilder.toString();
    }
}
